package com.javaee.service.impl;

import com.javaee.dao.userDao;
import com.javaee.domain.User;
import com.javaee.service.userService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class userServiceImpl implements userService {

    @Autowired
    private userDao userdao;

    @Override
    public String login(User user) {
        String Password = userdao.login(user.getName());
        if (Password == null) {
            return "用户名不存在";
        } else if (!Password.equals((user.getPassword()))) {
            return "密码错误";
        } else {
            return "验证成功";
        }
    }
    public boolean isnameExist(User user) {
        if(userdao.isnameExist(user)>0){
            return true;
        }
        else return false;
    }

    @Override
    public String register(User user) {
        if (isnameExist(user)) {
            return "用户名已存在";}
        else if (userdao.register(user) > 0) {
            return "注册成功";
        } else {
            // 处理其他可能的注册失败情况
            return "注册失败";
        }
    }
}
